package com.cqut.hfh.ordering.service.Impl;

import com.cqut.hfh.ordering.pojo.EhyModule;
import com.cqut.hfh.ordering.pojo.FoodIndent;
import com.cqut.hfh.ordering.pojo.FoodUser;
import com.cqut.hfh.ordering.service.IFodIndentService;
import com.cqut.li.mybatisutil.dao.base.Dao;
import com.cqut.li.mybatisutil.dao.base.EntityDao;
import com.cqut.li.mybatisutil.dao.base.SearchDao;
import com.cqut.li.mybatisutil.entity.base.Entity;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author LJH
 * @date 2019/6/25-14:25
 */
@Service
public class FodIndentServiceImpl implements IFodIndentService {

    @Resource
    private Dao dao;
    @Resource
    private EntityDao entityDao;
    @Resource
    private SearchDao searchDao;

    @Override
    public List<Map<String, Object>> getFodIndents(String limit, String page) {
        String joinEntity
                = " left join fod_user on fod_user.user_id = fod_indent.user_id "
                + " left join fod_merchant on fod_merchant.merchant_id = fod_indent.merchant_id ";
        String con = " 1=1 limit "+ (Integer.valueOf(page)-1)*Integer.valueOf(limit) + "," + limit ;

        List<Map<String, Object>> fi_list
                = searchDao.searchForeign(new String[]{"fod_indent.indent_id",
                        "merchant_name",
                        "fod_user.user_name",
                        "fod_user.user_phone",
                        "fod_indent.indent_name",
                        "fod_indent.indent_num",
                        "fod_indent.indent_price",
                        "fod_indent.isva",
                        "fod_indent.oper",
                        "fod_indent.pay",
                        "fod_indent.dis",
                        "fod_indent.optime"},
                Entity.getTableName(FoodIndent.class),
                joinEntity,
                null,
                null,
                con
                );

        return fi_list;
    }

    @Override
    public Integer getCount() {
        return searchDao.sqlCount("fod_indent");
    }

    @Override
    public int updateById(String indent_id) {
        return dao.deleteByID(indent_id, FoodIndent.class);
    }

    @Override
    public List<Map<String, Object>> getFodIndentsByName(String limit, String page, String indent_id) {

        String con = " indent_id like '%" + indent_id + "%' limit "
                + (Integer.valueOf(page)-1)*Integer.valueOf(limit) + "," + limit ;

        String joinEntity
                = " left join fod_user on fod_user.user_id = fod_indent.user_id "
                + " left join fod_merchant on fod_merchant.merchant_id = fod_indent.merchant_id ";

        List<Map<String, Object>> fi_list
                = searchDao.searchForeign(new String[]{"fod_indent.indent_id",
                        "merchant_name",
                        "fod_user.user_name",
                        "fod_user.user_phone",
                        "fod_indent.indent_name",
                        "fod_indent.indent_num",
                        "fod_indent.indent_price",
                        "fod_indent.isva",
                        "fod_indent.oper",
                        "fod_indent.pay",
                        "fod_indent.dis",
                        "fod_indent.optime"},
                Entity.getTableName(FoodIndent.class),
                joinEntity,
                null,
                null,
                con
        );

        return fi_list;
    }

    @Override
    public int updatePsById(String indent_id) {
        FoodIndent f = new FoodIndent();
        f.setDis("已派送");
        return entityDao.updatePropByID(f, indent_id);
    }
}
